package com.yt.file.common.config;

import org.csource.common.MyException;
import org.csource.fastdfs.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * FastDFS配置类
 */
@Component
public class FastDFSConfig implements InitializingBean {
    private static final Logger logger = LoggerFactory.getLogger(FastDFSConfig.class);

    @Override
    public void afterPropertiesSet() {
        try {
            // 获取配置文件路径并初始化FastDFS客户端
            String configPath = this.getClass().getResource("/config.properties").getPath();
            ClientGlobal.init(configPath);
            logger.info("FastDFS配置初始化成功");
        } catch (IOException | MyException e) {
            logger.error("FastDFS配置初始化失败", e);
            throw new RuntimeException("FastDFS配置初始化失败", e);
        }
    }
}